---
description: Using Hasura with an Azure Cosmos DB for PostgreSQL
title: 'Cloud: Using Hasura Cloud with an Azure Cosmos DB for PostgreSQL'
keywords:
  - hasura
  - docs
  - existing database
  - guide
  - azure
  - cosmos
sidebar_label: Azure Cosmos DB
sidebar_position: 6
---

import Thumbnail from '@site/src/components/Thumbnail';
import HeadingIcon from '@site/src/components/HeadingIcon';

# Connecting Hasura to an Azure Cosmos DB for PostgreSQL

## Introduction

This guide explains how to connect a new
[Azure Cosmos DB for PostgreSQL](https://learn.microsoft.com/en-us/azure/cosmos-db/postgresql/introduction) to a Hasura
instance, either on [Hasura Cloud](https://cloud.hasura.io?skip_onboarding=true) or via one of our
[self-hosted](/deployment/deployment-guides/index.mdx) solutions. If you're exploring Azure Cosmos DB for PostgreSQL,
check out their [docs](https://azure.microsoft.com/en-us/products/cosmos-db/#overview) before continuing below.

:::info Note

If you plan on using Hasura Cloud, which we recommend, follow steps 1 and 2 below. If you're self-hosting a Hasura
instance and already have a project running, skip to [step 3](#create-pg-db-azure).

:::

## Step 1: Sign up or log in to Hasura Cloud

Navigate to [Hasura Cloud](https://cloud.hasura.io/signup/?pg=docs&plcmt=body&cta=navigate-to-hasura-cloud&tech=default)
and sign up or log in.

## Step 2: Create a Hasura Cloud project {#create-hasura-project-azure}

On the Hasura Cloud dashboard, create a new project:

<Thumbnail src="/img/cloud-dbs/create-hasura-cloud-project.png" alt="Create Hasura Cloud project" width="1000px" />

After the project is initialized successfully, click on `Launch Console` to open the Hasura Console in your browser.

On the Hasura Console, navigate to the `Data` tab and choose `Connect Existing Database`. Hasura will prompt you for a
Postgres Database URL. We'll create this in the next step and then come back here.

<Thumbnail src="/img/cloud-dbs/existing-db-setup.png" alt="Hasura Cloud database setup" width="700px" />

## Step 3: Create a Cosmos DB on Azure {#create-pg-db-azure}

You can start a free trial with [Azure Cosmos DB](https://cosmos.azure.com/try/). Select Azure Cosmos DB for PostgreSQL
and click `Create`:

<Thumbnail src="/img/cloud-dbs/azure-cosmos/cosmos-create.png" alt="Create Azure Cosmos" width="1000px" />

After signing up, you're redirected to your database's home on your Azure portal.

## Step 4: Get the connection string {#get-db-url-azure-cosmos}

The structure of the database connection URL looks as follows:

```bash
postgres://<username>:<your_password>@<host>:<port>/<db_name>?sslmode=require
```

:::info Note

Be sure to update the password for the database before continuing. You can do this by clicking on the banner at the top
of the page.

:::

Click `Connection strings` in the side navigation:

<Thumbnail src="/img/cloud-dbs/azure-cosmos/cosmos-dashboard.png" alt="Azure Cosmos DB Dashboard" />

Copy the value labeled as `PostgreSQL connection URL`.

<Thumbnail src="/img/cloud-dbs/azure-cosmos/cosmos-connection-url.png" alt="Connection strings for the database" />

## Step 5: Finish connecting the database

Back on the Hasura Console, enter the database URL that we retrieved in [step 4](#get-db-url-azure-cosmos):

<Thumbnail src="/img/cloud-dbs/azure-cosmos/cosmos-connect.png" alt="Database setup" width="600px" />

Then click `Connect Database`.

:::info Note

For security reasons, it is recommended to set database URLs as
[env vars](/hasura-cloud/projects/env-vars.mdx#manage-project-env-vars) and using the env vars to connect to the
databases in place of the raw database URLs.

:::

Voilà. You are ready to start developing.

<Thumbnail src="/img/cloud-dbs/hasura-console.png" alt="Hasura Console" />

## Next steps

- You can check out our [30-Minute Hasura Basics Course](https://hasura.io/learn/graphql/hasura/introduction/) and other
  [GraphQL & Hasura Courses](https://hasura.io/learn/) for a more detailed introduction to Hasura.

- If using Hasura Cloud, you can also click the gear icon to manage your Hasura Cloud project. (e.g. add
  [collaborators](/hasura-cloud/projects/collaborators.mdx#manage-project-collaborators),
  [env vars](/hasura-cloud/projects/env-vars.mdx#manage-project-env-vars) or
  [custom domains](/hasura-cloud/domains.mdx#manage-project-domains)).

<Thumbnail src="/img/getting-started/project-manage.png" alt="Project actions" width="860px" />

:::info Note

For more information on which Azure Cosmos DB features we support, check out
[this page](/databases/feature-support.mdx).

:::
